using System.Collections.Generic;

namespace Gj
{
    public class RefData
    {
        private static Dictionary<string, List<string>> refMap = new Dictionary<string, List<string>>();

        public static void SetRef(string type, string old, string value)
        {
            requiredRef(type);
            int index = refMap[type].IndexOf(old);
            if (index == -1)
            {
                refMap[type].Add(value);
            }
            else
            {
                refMap[type][index] = value;
            }
        }

        public static void SetRef(string type, string oldValue, string oldLabel, string value, string label)
        {
            SetRef(type, oldValue + "-" + oldLabel, value + "-" + label);
        }

        public static void AddRef(string type, string value, string label1, string label2)
        {
            AddRef(type, value, label1 + " " + label2);
        }

        public static void AddRef(string type, string value, string label)
        {
            requiredRef(type);
            refMap[type].Add(value + "-" + label);
        }

        public static string[] GetRefList(string type)
        {
            requiredRef(type);
            List<string> list = refMap[type];
            string[] result = new string[list.Count];
            int index = 0;
            foreach (string s in list)
            {
                result[index] = s;
                index++;
            }
            return result;
        }

        private static void requiredRef(string type)
        {
            if (!refMap.ContainsKey(type)) refMap.Add(type, new List<string>()); 
        }
    }
}